//var channelsXmlFile = "/home/mohammed/xvd/channels.xml";
//var channelsXmlFile = "chrome:/content/channels.xml";
//var configXmlFile = "chrome:/content/config.xml";
var globalChannels;
var xItem;
var currentChannel;
var currentChannelIndex;
var previousChannelIndex;

var drmBxUser;
var drmBxPass;
var drmBxIp;

function getUserHome(){
		  var dirService = Components.classes["@mozilla.org/file/directory_service;1"].
					                   getService(Components.interfaces.nsIProperties); 
		  var homeDirFile = dirService.get("Home", Components.interfaces.nsIFile); // returns an nsIFile object
		  var homeDir = homeDirFile.path;
		  return ( homeDir );
}
function getChannelsXmlPath(){
		  //alert ( getUserHome() + "/.channels.xml" );
		  //return ("file://" + getUserHome() + "/.channels.xml" );
		  return (getUserHome() + "/.channels.xml" );
}
function getConfigXmlPath(){
		  //alert ( getUserHome() + "/.channels.xml" );
		  //return ("file://" + getUserHome() + "/.channels.xml" );
		  return (getUserHome() + "/.config.xml" );
}


function moveChannelSelectionDown(){
	var channelsList = document.getElementById('displayList');
	if ( channelsList.selectedItem == null )
		channelsList.selectItem( channelsList.getItemAtIndex( 0 ) );

	if ( ( channelsList.getRowCount() - 1 )  == channelsList.selectedIndex ){
		channelsList.selectItem( channelsList.getItemAtIndex( 0 ) );
	} else {
		channelsList.moveByOffset( 1 , true, false );
	}
}

function moveChannelSelectionUp(){
	var channelsList = document.getElementById('displayList');
	if ( channelsList.selectedItem == null )
		channelsList.selectItem( channelsList.getItemAtIndex( 0 ) );

	if ( channelsList.selectedIndex == 0 ){
		channelsList.selectItem(channelsList.getItemAtIndex( channelsList.getRowCount() - 1));
	} else {
		channelsList.moveByOffset( -1 , true, false );
	}
}


function getStream(){
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange  = function() { 
		if(xhr.readyState  == 4) {
			if(xhr.status  == 200){
				dump("GET channels successfull:" + xhr.responseText  + "\n");
			} else {
				document.ajax.dyn="Error code " + xhr.status;
			}
		}
	};

	dump (  'http://' + drmBxIp + '/video.m3u\n');
	xhr.open('GET', 'http://' + drmBxIp + '/video.m3u', false);
	xhr.setRequestHeader( "Authorization","Basic " + Base64.encode( drmBxUser + ":" + drmBxPass ) );
	xhr.send(null); 
	return ( xhr.responseText );
}






function loadXmlChannels(txt){
	dump ("load Xml\n");
	//dump ( txt );
	var xmlobject = (new DOMParser()).parseFromString(txt, "text/xml");
	var root = xmlobject.getElementsByTagName('channels')[0];
	//dump ( root.childNodes.item(0) );

	var channels = new Array();
	//dump(root.childNodes.length + "\n");
	for (var channel = 0; channel < root.childNodes.length; channel++) {
		//dump ( "iNode:" + channel );
		var node = root.childNodes.item(channel);
		//var id = ( node.childNodes[0].childNodes[0].nodeValue );
		var name = ( node.childNodes[0].childNodes[0].nodeValue );
		var zap = ( node.childNodes[1].childNodes[0].nodeValue );
		var stream = ( node.childNodes[2].childNodes[0].nodeValue );
		channels[ channel ] = new Array;
		channels[ channel ]["name"] = name;
		channels[ channel ]["stream"] = stream;
		channels[ channel ]["zap"] = zap;
		//dump ( zap );
	}
	globalChannels = channels;
	return ( channels );
}


function zapChannel(ref){
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange  = function() { 
		if(xhr.readyState  == 4) {
			dump("zap status" + xhr.status + "\n");
			alert( xhr.responseText );
			if(xhr.status  == 200) {
				dump ("zap successfull");
			} else {
				dump ("Zap failure, " + xhr.status );
				document.ajax.dyn="Error code " + xhr.status;
			}
		}
	};


	dump (  "Zap to url http://" + drmBxIp + "/cgi-bin/zapTo?path=" + ref + "\n" );
	xhr.open('GET', "http://" + drmBxIp + "/cgi-bin/zapTo?path=" + ref , false);
	xhr.setRequestHeader( "Authorization","Basic " + Base64.encode( drmBxUser + ":" + drmBxPass ) );
	xhr.send(null); 
}




function selectChannel(){
	var channelsList = document.getElementById('displayList');
	//dump( channelsList.selectedItem.name + "\n");


	if ( currentChannel == channelsList.selectedItem.value  ){
		vlcviewer.video.toggleFullscreen();
		return;
	}
	//try { vlcviewer.playlist.items.clear() } catch (e){dump( "\nException Caught in clear: "+ e +"\n");}
	
	try { vlcviewer.playlist.stop(); } catch (e) { dump( "Exception Caught: stop " + e + "\n" ); }
	try { vlcviewer.playlist.items.clear() } catch (e){dump( "\nException Caught in clear: "+ e +"\n");}

	sleep(1);
	if ( xItem != null ) {
		dump ( "vlcviewer.playlist.items.remove(" + xItem + ")\n" );
		try {
			vlcviewer.playlist.items.remove(xItem);
		} catch (e){
			dump( "\nException Caught in remove: "+ e+"\n");
		}

	}

	dump( "playlist count: " + vlcviewer.playlist.items.count + "\n" );
	dump( "Swtiching to channel: " + channelsList.selectedItem.label + "\n");

	sleep(1);
	//var simpleMessage = "zap to: " +  channelsList.selectedItem.value ;
	//document.getElementById("serviceName").value = simpleMessage ;
	zapChannel( channelsList.selectedItem.value );

	sleep(1);

	


	previousChannelIndex  = currentChannelIndex;
	currentChannelIndex = channelsList.selectedIndex;
	currentChannel = channelsList.selectedItem.value;
	getEPG();
}



function recallPrevousChannel(){
	var channelsList = document.getElementById('displayList');
	channelsList.selectItem( channelsList.getItemAtIndex(  previousChannelIndex ) );
	selectChannel();
}



function reloadFavorites(){
	clearDisplayList();
	var channels = loadXmlFile(); 
	var titleLabel = document.getElementById("displayListLabel");
	titleLabel.value = "Channels List";
	var channelsList = document.getElementById('displayList');
	for ( var i = 0; i < channels.length; i++ ){
		var listItem = channelsList.appendItem(channels[i]["name"] , channels[i]["ref"]  );
		listItem.ondblclick = Go;
	}
}


function loadXmlFile(){
	var myXMLHTTPRequest = new XMLHttpRequest();
	//myXMLHTTPRequest.open("GET", getChannelsXmlPath() , false);
	myXMLHTTPRequest.open("GET","file:"+ getChannelsXmlPath() , false);
	myXMLHTTPRequest.send(null);
	var xmlobject = (new DOMParser()).parseFromString(myXMLHTTPRequest.responseText, "text/xml");
	var root = xmlobject.getElementsByTagName('channels')[0];

	var channels = new Array();
	for (var channel = 0; channel < root.childNodes.length; channel++) {
		var node = root.childNodes.item(channel);
		var name = ( node.childNodes[0].childNodes[0].nodeValue );
		var ref = ( node.childNodes[1].childNodes[0].nodeValue );
		channels[ channel ] = new Array;
		channels[ channel ]["name"] = name;
		channels[ channel ]["ref"] = ref;
	}
	
	globalChannels = channels;
	return ( channels );
}


function sleep(naptime){
	naptime = naptime * 1000;
	var sleeping = true;
	var now = new Date();
	var alarm;
	var startingMSeconds = now.getTime();
	//alert("starting nap at timestamp: " + startingMSeconds + "\nWill sleep for: " + naptime + " ms");
	while(sleeping){
		alarm = new Date();
		alarmMSeconds = alarm.getTime();
		if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
	}      
	//alert("Wakeup!");
}

function Go(){
	var titleLabel = document.getElementById("displayListLabel");
	if ( titleLabel.value == "Channels List" ){
		selectChannel();
	} else {
		selectRef();
	}
}


function Main() {
		  loadConfigXmlFile();
		  reloadFavorites();
		  start();
		  //runProcess();
		  var channelsList = document.getElementById('displayList');
		  channelsList.selectItem(channelsList.getItemAtIndex( 0 ));
		  //fetchReferenceServices("1:15:fffffffc:12:0:0:0:0:0:0:");
		  //getChannelsAsXml();
}

function fullVolume(){
	vlcviewer.audio.volume = 200;
}

function increaseVolume(){
	vlcviewer.audio.volume = vlcviewer.audio.volume + 30;
}
function decreaseVolume(){
	vlcviewer.audio.volume = vlcviewer.audio.volume - 30;
}

function toggleMute(){
	vlcviewer.audio.toggleMute()
}

var menu_on;
function route(data){ 
	dump ("taking action on irCommand:" + data );
	var command = data.replace(/\n/g, "");
	try {
		 if ( vlcviewer.video.fullscreen ) { 
			 menu_on = 0;
		 } else {
			 menu_on = 1;
		 }
	} catch (e) {
		menu_on = 1;
	}
	if ( menu_on == 0 ){
		if(command  == "menu") {
			vlcviewer.video.toggleFullscreen();
			menu_on = 1;
		}
		if(command  == "play") {
			toggleMute();
		}

		if(command  == "up") {
			increaseVolume();
		}
		if(command  == "down") {
			decreaseVolume();
		}
		if(command  == "right") {
			moveChannelSelectionDown();
			selectChannel();
		}
		if(command  == "left") {
			moveChannelSelectionUp()
			selectChannel();
		}

	} else {
		if(command  == "down") {
			moveChannelSelectionDown();
		}
		if(command  == "up") {
			moveChannelSelectionUp()
		}
		if(command  == "play") {
			selectChannel();
		}
		if(command  == "menu") {
			vlcviewer.video.toggleFullscreen();
			menu_on = 0;
		}
		if(command  == "left") {
			recallPrevousChannel();
		}

	}
}


var serverSocket;

function start()
{
	var listener =
	{
onSocketAccepted : function(socket, transport)
		   {
			   try {
				   var outputString = "HTTP/1.1 200 OK\n" +
					   "Content-type: text/plain\n\n" +
					   "Hello there " + transport.host + "\n";
				   var stream = transport.openOutputStream(0,0,0);
				   stream.write(outputString,outputString.length);

				   var istream = transport.openInputStream(0,0,0);
				   var instream = Components.classes["@mozilla.org/scriptableinputstream;1"]
					   .createInstance(Components.interfaces.nsIScriptableInputStream);
				   instream.init(istream);

				   var dataListener = { 
data : "",
       onStartRequest: function(request, context){},
       onStopRequest: function(request, context, status){
	       //dump ( "connection closed \n ");
	       //instream.close();
	       //listener.finished(this.data);
	       //stream.close();
       },
onDataAvailable: function(request, context, inputStream, offset, count){
			 //this.data += instream.read(count);
			 //this.data = instream.read(count);
			 var dataReceived =  instream.read(count);
			 var irCommand = dataReceived.replace(/\r\n/, "").substring(0,25).replace(/GET \/\?action=/,"").replace(/\ .*$/,"");

	       //stream.close();
			 //route ( instream.read(count) );
			 route(irCommand);
			 //stream.close();
			 instream.close();
		 }
				   };

				   var pump = Components.
					   classes["@mozilla.org/network/input-stream-pump;1"].
					   createInstance(Components.interfaces.nsIInputStreamPump);
				   //pump.init(istream, -1, -1, 0, 0, false);
				   pump.init(istream, -1, -1, 0, 0, true);
				   pump.asyncRead(dataListener,null);

				   stream.close();
			   } catch(ex2){ dump("::"+ex2); }
		   },

onStopListening : function(socket, status){}
	};

	try {
		serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
			.createInstance(Components.interfaces.nsIServerSocket);

		serverSocket.init(7055,false,-1);
		serverSocket.asyncListen(listener);
	} catch(ex){ dump(ex); }

	//document.getElementById("status").value = "Started";
}

function stop()
{
	if (serverSocket) serverSocket.close();
	//document.getElementById("status").value = "Stopped";
}



function getEPG(){
	dump ("get epg");
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange  = function() { 
		if(xhr.readyState  == 4) {
			dump("zap status" + xhr.status + "\n");
			if(xhr.status  == 200) {
				//alert( xhr.responseText );
				//dump ( xhr.responseText );
				processEPG( xhr.responseText );
			} else {
				dump ("EPG failure, " + xhr.status );
				document.ajax.dyn="Error code " + xhr.status;
			}
		}
	};
	//xhr.open('GET', url , false, "root" , "");
	url = "http://" + drmBxIp + "/data";
	xhr.open('GET', url , true);
	xhr.setRequestHeader( "Authorization","Basic " + Base64.encode( drmBxUser + ":" + drmBxPass ) );
	xhr.send(null); 
}



function processEPG( txt ){
	var code = txt.replace(/<!--?.*-->/ig, "");
	var code = code.replace(/\n/g, "");
	var code = code.replace(/<html>.*<script>/ig, "");
	var code = code.replace(/<\/script><\/body><\/html>/ig, "");
	eval( code );
	//dump ( code );
	//dump ( serviceName + "\n");
	//dump ( vlcparms );
	document.getElementById("nowSt").value = nowT + " " + nowSt + " " + nowD;
	document.getElementById("nextSt").value = nextT + " " + nextSt + " " + nextD;

	// if the service is the same, just stop.
	if ( document.getElementById("serviceName").value == serviceName ){
			  dump ("service: " + serviceName + " allready loaded.");
			  return;
	}
	document.getElementById("serviceName").value = serviceName ;


	//var simpleMessage = "add stream: " + vlcparms;
	//document.getElementById("serviceName").value = simpleMessage ;


	options = new Array(":crop=16:10");
	xItem = vlcviewer.playlist.add( vlcparms , null , options );

	//sleep(1);
	dump( "vlc play: " + xItem + "\n" );
	dump( "vlc play: " + vlcviewer.playlist.items.count + "\n" );

	vlcviewer.playlist.playItem(xItem);
	vlcviewer.log.verbosity = 0;

}


function fetchReferenceServices( ref ){
	dump ( "fetchReferenceServices ");
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange  = function() { 
		if(xhr.readyState  == 4) {
			dump("zap status" + xhr.status + "\n");
			if(xhr.status  == 200) {
				//alert( xhr.responseText );
				dump ( xhr.responseText );
				if ( xhr.responseText == "E: error during list services" ) {
					if ( addToFavorites() == true )
						alert("channels has been added to your favorites");
				} else {
					var result = xhr.responseText.split("\n");
					clearDisplayList();
					populateList(result);
				}
			} else {
				dump ("EPG failure, " + xhr.status );
				document.ajax.dyn="Error code " + xhr.status;
			}
		}
	};
	var url = "http://" + drmBxIp +  "/cgi-bin/getServices?ref=" + ref;
	dump ( "\n" + url + "\n" );
	xhr.open('GET', url , true);
	xhr.setRequestHeader( "Authorization","Basic " + Base64.encode( drmBxUser + ":" + drmBxPass ) );
	xhr.send(null); 
}

function clearDisplayList(){
	var displayList = document.getElementById('displayList');
	while(displayList.getRowCount() != 0) {
		displayList.removeItemAt(0);
	}
}
function populateList(list){
	var currentListName = list[list.length - 2].split(";")[1];
	var titleLabel = document.getElementById("displayListLabel");
	titleLabel.value = currentListName;
	var displayList = document.getElementById('displayList');
	clearDisplayList();

	//displayList.setAttribute("rows", list.length - 2 );
	displayList.setAttribute("rows", 25);
	for ( var i = 0; i < ( list.length ) - 2; i++ ){
		var listItem = displayList.appendItem(list[i].split(";")[1],list[i].split(";")[0]);
		listItem.ondblclick = Go;
	}
	//document.getElementById("displayList").addEventListener("dblclick" , selectRef() , true);
}


function selectRef(){
	fetchReferenceServices( document.getElementById("displayList").selectedItem.value );
}

function addToFavorites(){
	var ref =  document.getElementById("displayList").selectedItem.value;
	var name = document.getElementById("displayList").selectedItem.label;
	/*var myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", "file:/home/mohammed/xul/xvd/channels.xml", false);
	myXMLHTTPRequest.send(null);

	var xmlobject = (new DOMParser()).parseFromString(myXMLHTTPRequest.responseText, "text/xml");*/
	var xmlobject = loadFavoritesFile();
	var root = xmlobject.getElementsByTagName('channels')[0];


	for (var channel = 0; channel < root.childNodes.length; channel++) {
		var node = root.childNodes.item(channel);
		var ref_old = ( node.childNodes[1].childNodes[0].nodeValue );
		if ( ref == ref_old ) {
			alert ( "this channel is allready in your favorites" );
			return(false);
		}
	}



	var newChannel = xmlobject.createElement("channel");

	var newChannelName = xmlobject.createElement("name");
	var newChannelNameText = xmlobject.createTextNode(name);
	newChannelName.appendChild( newChannelNameText );

	var newChannelRef = xmlobject.createElement("ref");
	var newChannelRefText = xmlobject.createTextNode(ref);
	newChannelRef.appendChild( newChannelRefText );

	newChannel.appendChild( newChannelName );
	newChannel.appendChild( newChannelRef );

	root.appendChild( newChannel );
	save ( xmlobject );
	return(true);

}

function loadFavoritesFile(){
	var ref =  document.getElementById("displayList").selectedItem.value;
	var name = document.getElementById("displayList").selectedItem.label;
	var myXMLHTTPRequest = new XMLHttpRequest();
	myXMLHTTPRequest.open("GET", "file:" + getChannelsXmlPath() , false);
	//myXMLHTTPRequest.open("GET", getChannelsXmlPath() , false);
	myXMLHTTPRequest.send(null);
	var xmlobject = (new DOMParser()).parseFromString(myXMLHTTPRequest.responseText, "text/xml");
	return xmlobject
}
function removeFromFavorites(){
	var refToDelete =  document.getElementById("displayList").selectedItem.value;
	var nameToDelete = document.getElementById("displayList").selectedItem.label;

	var xmlobject = loadFavoritesFile();
	var root = xmlobject.getElementsByTagName('channels')[0];

	for (var channel = 0; channel < root.childNodes.length; channel++) {
		var node = root.childNodes.item(channel);
		var name = ( node.childNodes[0].childNodes[0].nodeValue );
		var ref = ( node.childNodes[1].childNodes[0].nodeValue );
		if ( ref == refToDelete ) {
			root.removeChild( node );
			break;
		}
	}

	save ( xmlobject );
	reloadFavorites();
}


function moveFavorite(destination){
	var refToMove =  document.getElementById("displayList").selectedItem.value;
	var nameToMove = document.getElementById("displayList").selectedItem.label;

	var xmlobject = loadFavoritesFile();
	var root = xmlobject.getElementsByTagName('channels')[0];

	var selectedItem = 0;
	for (var channel = 0; channel < root.childNodes.length; channel++) {
		var node = root.childNodes.item(channel);
		var name = ( node.childNodes[0].childNodes[0].nodeValue );
		var ref = ( node.childNodes[1].childNodes[0].nodeValue );
		if ( ref == refToMove ) {
			if (destination == "up" ){
				root.insertBefore( node , root.childNodes.item(channel - 1) );
				selectedItem = channel - 1;
			} else {
				root.insertBefore( root.childNodes.item(channel + 1) , node );
				selectedItem = channel + 1;
			}
			break;
		}
	}

	save ( xmlobject );
	reloadFavorites();
	var channelsList = document.getElementById('displayList');
	channelsList.selectItem(channelsList.getItemAtIndex( selectedItem ));
}




function save(newXml) {
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	} catch (e) {
		alert("Permission to save file was denied.");
	}
	var file = Components.classes["@mozilla.org/file/local;1"]
		.createInstance(Components.interfaces.nsILocalFile);
	file.initWithPath( getChannelsXmlPath() );
	if ( file.exists() == false ) {
		alert( "Creating file... " );
		file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
	}
	var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
		.createInstance( Components.interfaces.nsIFileOutputStream );
	outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
	//var output = document.getElementById('blog').value;
	var output = (new XMLSerializer()).serializeToString(newXml);
	var result = outputStream.write( output, output.length );
	outputStream.close();

}




function runProcess(){
	var file = Components.classes["@mozilla.org/file/local;1"]
		.createInstance(Components.interfaces.nsILocalFile);
	file.initWithPath("/usr/bin/irexec");

	var process = Components.classes["@mozilla.org/process/util;1"]
		.createInstance(Components.interfaces.nsIProcess);
	process.init(file);

	var args = ["/home/mohammed/.lircrc"];
	process.run(false, args, args.length);

}

function rebootReceiver(){
	//alert( Base64.encode ( drmBxUser + ":" + drmBxPass ) );

	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange  = function() { 
		if(xhr.readyState  == 4) {
			dump( "reboot status: " + xhr.status + " " +  xhr.responseText + "\n" );
			if(xhr.status  == 200) {
				dump ("reboot done");
			} else {
				dump ("reboot failed, " + xhr.status );
				document.ajax.dyn="Error code " + xhr.status;
			}
		}
	};

	var url = "http://" + drmBxIp + "/cgi-bin/admin?command=reboot";
	dump ("request to url: " + url );
	xhr.open('GET', url , true);
	xhr.setRequestHeader( "Authorization","Basic " + Base64.encode( drmBxUser + ":" + drmBxPass ) );
	xhr.send(null); 
}




function writeConfigurtionsFile(_newXml) {
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	} catch (e) {
		alert("Permission to save file was denied.");
	}
	var file = Components.classes["@mozilla.org/file/local;1"]
		.createInstance(Components.interfaces.nsILocalFile);
	file.initWithPath( getConfigXmlPath() );
	if ( file.exists() == false ) {
		alert( "Creating file... " );
		file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
	}
	var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
		.createInstance( Components.interfaces.nsIFileOutputStream );
	outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
	//var output = document.getElementById('blog').value;
	//var output = (new XMLSerializer()).serializeToString(_newXml);
	//var result = outputStream.write( output, output.length );
	var result = outputStream.write( _newXml , _newXml.length   );
	outputStream.close();

}


function saveConfigurations(){
		  var userTextBox = document.getElementById('drmBxUser');
		  var passTextBox = document.getElementById('drmBxPass');
		  var ipAddressTextBox = document.getElementById('drmBxIpAddress');
		  var s = '<?xml version="1.0"?>\n<configurations><config><user>' + userTextBox.value +
					 "</user><password>" + passTextBox.value + 
					 "</password><ip>" + ipAddressTextBox.value + 
					 "</ip></config></configurations>";
		  //alert ( s );
		  writeConfigurtionsFile ( s );

}

function setConfigDialogueValues(){
		  loadConfigXmlFile();
		  var userTextBox = document.getElementById('drmBxUser');
		  userTextBox.value = drmBxUser; 
		  var passTextBox = document.getElementById('drmBxPass');
		  passTextBox.value = drmBxPass; 
		  var ipAddressTextBox = document.getElementById('drmBxIpAddress');
		  ipAddressTextBox.value = drmBxIp; 
}
function loadConfigXmlFile(){
		  var myXMLHTTPRequest = new XMLHttpRequest();
		  myXMLHTTPRequest.open("GET", "file:" +  getConfigXmlPath() , false);
		  myXMLHTTPRequest.send(null);
		  var xmlobject = (new DOMParser()).parseFromString(myXMLHTTPRequest.responseText, "text/xml");

		  var root = xmlobject.getElementsByTagName('configurations')[0];
		  var node = root.childNodes.item(0);

		try {
				  var user = ( node.childNodes[0].childNodes[0].nodeValue );
		} catch (e){ user = ""; }
		try {
		  var pass = ( node.childNodes[1].childNodes[0].nodeValue );
		} catch (e){ pass = ""; }
		try {
		  var ipAddress = ( node.childNodes[2].childNodes[0].nodeValue );
		} catch (e){ ipAddress = ""; }

		  drmBxUser = user;
		  drmBxPass = pass;
		  drmBxIp = ipAddress;
}


function showConfigWindow(){
		  window.open("chrome://xvd/content/config.xul",
								"Configurations", 
								"chrome,width=280,height=160");
}
